package edu.xjtu.jih.login;

import edu.xjtu.jih.common.Utils;
import org.apache.ibatis.session.SqlSession;

public class LoginService {
    public boolean checkLogin(LoginDto dto) {

        SqlSession sqlSession = Utils.openSession();

        try{
            LoginDao dao = sqlSession.getMapper(LoginDao.class);
            // System.out.println("1");
            int count = dao.findUserCountByIdAndPwd(dto);//select count(u_id) from t_teacher where u_id = 'xxx' and u_pwd = 'cccc'
            // System.out.println(count);

            int ID = dao.findUserID(dto);
            dto.setU_id(ID);

            sqlSession.commit();

            return count > 0;
        }catch(Exception e){
            sqlSession.rollback();
            throw new RuntimeException(e);
        }finally{
            sqlSession.close();
        }
    }
}
